///////////////////////////////////////////////////////////////////////////////
// Name:        adaclassmod.cpp
// Purpose:     Adaclassmod function
// Copyright:   (c) 2006, Ivan Laptev, TT Solutions
// License:     GPL, Please contact us for commercial license.
//              http://www.tt-solutions.com/
///////////////////////////////////////////////////////////////////////////////
#include "objectdet/adaclassmod.h"

#include "objectdet/localhistlinclass.h"

// particular stage check test function
// std::pair<bool,double> adaclassmod(StageModel const & stagemodel, CvMat * imgproc, Rect const & rect)
std::pair<bool,double> adaclassmod(Stage const & stage,
                                   arrMat integral_block_histogram,
                                   size_t channels,
                                   size_t left, size_t top,
                                   size_t width, size_t height)
{
    double dfce = 0;
    /**
     * For every rule in the stagemodel, calculate some coeff on the subwindow
     * and add the rule.Alpha with either plus or minus sign to the total summ.
     *
     * If the summ passes stagemodel threshhold, then return true
     */
//    size_t members_num = stage.rules.size();
    StageRules::const_iterator rule_it  = stage.rules.begin();
    StageRules::const_iterator rule_end = stage.rules.end();
    for (; rule_it != rule_end; ++rule_it)
    {
        bool const curr_y = localhistlinclass(*rule_it,
                                              integral_block_histogram,
                                              channels,
                                              left, top, width, height);

        dfce += (curr_y ? rule_it->Alpha : -rule_it->Alpha);
    }

    return std::make_pair<bool,double>(dfce >= stage.stage_threshold, dfce);
}

